package cos470_assignment1

class BooksService {

  boolean transactional = false

    def getInitalBook() {
        return new Books(title: "Grails In Action", author: "Smith & Ledbrook", description: "A comprehensive guide to the Grails framework.")	
    }

    def getRandomBook() {
	
        def allBooks = Books.list()
        def randomBook = null
        if (allBooks.size() > 0) {
            def randomIdx = new Random().nextInt(allBooks.size())
            randomBook = allBooks[randomIdx]
        } 
		else {
            randomBook = getInitalBook()
        }		
        return randomBook

    }
}
